<?php use_helper('Number') ?>
<?php use_helper('Javascript') ?>

<div class="center_title">
    <?php echo __('My cart') ?>
</div>

<div class="center_text">
    <div class="text_item">
        <?php if( get_user_id() ): ?>
        <div>
            <?php echo link_to(
                            image_tag(
                                'history.png'
                                , array(
                                    'border' => '0'
                                    , 'alt' => __('view shopping history')
                                    , 'title' => __('view shopping history')
                                    , 'style' => 'width: 24px; height: 24px; padding: 3px; margin-bottom: -10px;'
                                )
                            )
                            , 'cart/mylist'
                        ) ?>
            <?php echo link_to(
                            __('view shopping history')
                            , 'cart/mylist'
                        ) ?>
        </div>
        <?php endif; ?>

    <?php if ($receipt):?>
        <?php $i = 1; ?>
        <?php if ( $receipt->getReceiptItemsQnt() > 0 ): ?>
        <table width="100%" class="cart" cellpadding="2" cellspacing="1">
            <tr>
                <th width="5%"><?php echo __('No.'); ?></th>
                <th width="15%"><?php echo __('Item code'); ?></th>
                <!--<th width="5%"><?php echo __('Info')?></th>-->
                <th width="60%" align="left"><?php echo __('Item name')?></th>
                <!--<th width="10%"><?php echo __('Price')?></th>
                <th width="15%"><?php echo __('Quantity')?></th>-->
                <th width="15%" align="right" nowrap="nowrap"><?php echo __('Price')?></th>
                <th width="5%"><?php echo __('Delete'); ?></th>
            </tr>
            <?php foreach ($arItems as $item):?>
                <tr>
                    <td align="center">
                        <?php echo $i++; ?>
                    </td>
                    <td align="center">
                        <?php $product = ProductPeer::retrieveByPK($item->getObjId()); ?>
                        <?php echo $product->getCode() ?>
                    </td>
                    <!--<td align="center">
                        <?php echo link_to(
                                        image_tag(
                                            'info.png'
                                            , array(
                                                'border' => '0'
                                                , 'alt' => __('info')
                                                , 'title' => __('info')
                                                //, 'style' => 'margin: -2px;'
                                            )
                                        )
                                    , 'product/show?id=' . $item->getReceiptId()
                                       , array(
                                           'class' => ''
                                        )
                                    ) ?>
                    </td>-->
                    <td align="left" nowrap="nowrap">
                       <?php if(get_user_id()): ?>
	                       <?php echo link_to($item->getName()
	                                           , 'pradmin/list?filters[id]=' . $item->getObjId() . '&filter=1'
	                                           )?>
                       <?php else: ?>
                            <?php echo link_to($item->getName()
                                           , 'product/show?id=' . $item->getObjId()
                                           )?>
                       <?php endif; ?>
                    </td>
                    <!--<td nowrap="nowrap" align="center"><?php echo format_currency($item->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?></td>
                    <td>
                            <?php echo form_tag('cart/edit') ?>
                            <?php echo input_hidden_tag('qnt', 1) ?>
                            <?php echo input_hidden_tag('id', $item->getId()) ?>
                            <?php echo submit_image_tag(
                                                    'basket_add.png'
                                                    , array(
                                                        'border' => '0'
                                                        , 'alt' => __('add')
                                                        , 'title' => __('add')
                                                        , 'style' => 'margin-bottom: -4px;'
                                                    )
                                                )?>
                            </form>
        
                   </td>-->
                    <td align="right" nowrap="nowrap"><?php echo format_currency($item->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR'))*$item->getQuantity(), $sf_user->getAttribute('currency', 'EUR')) ?></td>
                    <td align="center">
                        <?php echo link_to(
                                        image_tag(
                                            'cross.png'
                                            , array(
                                                'border' => '0'
                                                , 'alt' => __('remove')
                                                , 'title' => __('remove')
                                            )
                                        )
                                        , 'cart/remove?id='.$item->getId()
                                    ) ?>
                    </td>
                </tr>
                
            <?php endforeach; ?>
        
            <tr>
                <th colspan="3"></th>
                <th align="right" nowrap="nowrap">
                    <?php echo __('Total') ?>:&nbsp;&nbsp;<?php echo $receipt->getItemsQnt(); ?>&nbsp;&nbsp;&nbsp;
                    <?php echo format_currency($receipt->getPriceByCurrencyCode($sf_user->getAttribute('currency', 'EUR')), $sf_user->getAttribute('currency', 'EUR')) ?></th>
                <th></th>
            </tr>
        </table>
        <div class="cart_actions">
            <?php echo link_to(
                            image_tag(
                                'empty_basket.png'
                                , array(
                                    'border' => '0'
                                    , 'alt' => __('empty cart')
                                    , 'title' => __('empty cart')
                                    , 'style' => 'margin: -2px;'
                                )
                            )
                            , 'cart/emptycart'
                        ) ?>
            <?php echo link_to(
                            __('empty cart')
                            , 'cart/emptycart'
                        ) ?>
            <?php /* echo link_to(
                            image_tag(
                                'basket_checkout.png'
                                , array(
                                    'border' => '0'
                                    , 'alt' => __('continue shopping')
                                    , 'title' => __('continue shopping')
                                    , 'style' => 'margin: 0 0 -2px 10px;'
                                )
                            )
                            , 'xxx'
                        )*/ ?>
            <?php /*echo link_to(
                            __('continue shopping')
                            , 'xxx'
                        )*/ ?>
            <?php echo link_to(
                            image_tag(
                                'basket_pay.png'
                                , array(
                                    'border' => '0'
                                    , 'alt' => __('pay')
                                    , 'title' => __('pay')
                                    , 'style' => 'margin: 0 0 -2px 10px;'
                                )
                            )
                            , 'cart/confirm'
                        ) ?>
            <?php echo link_to(
                            __('pay')
                            , 'cart/confirm'
                        ) ?>
        </div>
        <div style="clear: both;"></div>
    <?php else: ?>
        <p>
            <?php echo __('Cart is empty') ?>.
        </p>
    <?php endif; ?>
    <?php endif; ?>

    </div>
</div>

<script>

// Whether we added smth
var gPrevItemId = 0;

function OnCartItemAdded(id)
{
    // Hide result of previous buy
    if( gPrevItemId > 0 )
    {
    	jQuery('#ci_' + gPrevItemId).hide();
    }
    gPrevItemId = id;
//  alert('Item is added');
    jQuery('#ci_' + id).update('Added').show();
//    alert($('divCartStatus'));
}

function OnCartItemFailed(id)
{
    // Hide result of previous buy
    if( gPrevItemId > 0 )
    {
    	jQuery('#ci_' + gPrevItemId).hide();
    }
    gPrevItemId = id;
//    alert('Item failed');
    jQuery('#ci_' + id).update('Fail').show();
//    $('feedback').show();
//    alert($('divCartStatus'));
}

</script>
